package com.are.odisea;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Servlet implementation class SrvAsigPermiso
 */
@WebServlet("/SrvAsigPermiso")
public class SrvAsigPermiso extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SrvAsigPermiso() {
        super();
        // TODO Auto-generated constructor stub
    }
    
    protected void ProcesarPeticion(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
    	response.setContentType("text/html;charset=ISO-8859-1");
    	PrintWriter out = response.getWriter();
    	String usuario = (String)request.getParameter("usuario");
    	String iddoc = (String)request.getParameter("iddoc");
    	
    	db conexion = null;
    	try {
			conexion = new db();
			
			PermisosDoc perdoc = new PermisosDoc(conexion);
			perdoc.setId_doc(iddoc);
			perdoc.setUsuario(usuario);
			if (!perdoc.AsigPermiso()) {
				out.print("Se asigno el permiso de forma exitosa");
			}else {
				out.print("Se produjo un error al asignar el permiso");
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			out.println(e.getMessage());
		}finally {
			if (conexion != null){
				try {
					conexion.Close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					//out.print("NO se conecto a la base de datps");
					out.println(e.getMessage());
				}
			}
		}
    	
    	
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		ProcesarPeticion(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		ProcesarPeticion(request, response);
	}

}
